<html>
<head><meta charset="utf-8"><title>source_to_def and attribute macros · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/source_to_def.20and.20attribute.20macros.html">source_to_def and attribute macros</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="241652098"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/source_to_def%20and%20attribute%20macros/near/241652098" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/source_to_def.20and.20attribute.20macros.html#241652098">(Jun 05 2021 at 19:14)</a>:</h4>
<p>I'm looking into how to fix <a href="https://github.com/rust-analyzer/rust-analyzer/issues/9142">https://github.com/rust-analyzer/rust-analyzer/issues/9142</a>, aaand this looks potentially quite difficult, since any syntactical item might actually be a macro call. There doesn't happen to be a convenient place to check for this and have everything magically work, right?</p>



<a name="241688594"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/source_to_def%20and%20attribute%20macros/near/241688594" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/source_to_def.20and.20attribute.20macros.html#241688594">(Jun 06 2021 at 12:07)</a>:</h4>
<p>Yeah, I think this is fundamentally tricky.....</p>
<p>Basically, the problem with this is that <code>source2def(src).src == src</code> equality <em>does not</em> hold with attributes</p>



<a name="241688658"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/source_to_def%20and%20attribute%20macros/near/241688658" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/source_to_def.20and.20attribute.20macros.html#241688658">(Jun 06 2021 at 12:08)</a>:</h4>
<p>That is, we start with annotated fn node, but should get a def whose source is actually in an expanded file</p>



<a name="241689560"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/source_to_def%20and%20attribute%20macros/near/241689560" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/source_to_def.20and.20attribute.20macros.html#241689560">(Jun 06 2021 at 12:31)</a>:</h4>
<p>well in principle, there just is no def for the original fn ast node, is there?</p>



<a name="241689618"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/source_to_def%20and%20attribute%20macros/near/241689618" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/source_to_def.20and.20attribute.20macros.html#241689618">(Jun 06 2021 at 12:32)</a>:</h4>
<p>it's like calling <code>to_def</code> on a macro call</p>



<a name="241689868"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/source_to_def%20and%20attribute%20macros/near/241689868" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/source_to_def.20and.20attribute.20macros.html#241689868">(Jun 06 2021 at 12:39)</a>:</h4>
<p>so I guess that the IDE functionality should first be descending into the macro calls, but it doesn't because it's only looking for <code>MacroCall</code> nodes? <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span></p>



<a name="241689949"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/source_to_def%20and%20attribute%20macros/near/241689949" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/source_to_def.20and.20attribute.20macros.html#241689949">(Jun 06 2021 at 12:41)</a>:</h4>
<blockquote>
<p>there just is no def for the original fn ast node, is there?</p>
</blockquote>
<p>unless the node gets passed through completely by the attribute of course, then it might be arguable that there is... but I'm not sure whether it would be necessary or helpful to do that</p>



<a name="241690063"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/source_to_def%20and%20attribute%20macros/near/241690063" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/source_to_def.20and.20attribute.20macros.html#241690063">(Jun 06 2021 at 12:43)</a>:</h4>
<p>i.e. in <code>descend_into_macros</code>, we need to not just look for <code>MacroCall</code>s, but also any ancestors annotated with proc macro attributes?</p>



<a name="241690167"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/source_to_def%20and%20attribute%20macros/near/241690167" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/source_to_def.20and.20attribute.20macros.html#241690167">(Jun 06 2021 at 12:45)</a>:</h4>
<p>yeah I played around with <code>descend_into_macros</code> the other day, that might get us some of the way there already</p>



<a name="241838081"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/source_to_def%20and%20attribute%20macros/near/241838081" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/source_to_def.20and.20attribute.20macros.html#241838081">(Jun 07 2021 at 20:44)</a>:</h4>
<p>I've changed <code>descend_into_macros</code> to work with attribute macro, and it seems to work when printing the original and remapped token. I've also changed <code>syntax_highlighting.rs</code> to account for attribute macros and descend into them, but somehow all identifiers in the invocation stay unresolved. Any idea what might cause this? Do we have any way to debug the token mapping?</p>



<a name="242061560"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/source_to_def%20and%20attribute%20macros/near/242061560" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/source_to_def.20and.20attribute.20macros.html#242061560">(Jun 09 2021 at 13:08)</a>:</h4>
<p>This is now largely fixed, but some way to debug <code>TokenMap</code> operations would still be nice</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>